table.COPY_RECORDS_TO Function

Syntax

Result as C = Table.Copy_Records_To(C Tablename [,C Filter_Expression ])

Arguments

Tablename

The name of the table to receive the copied records.

Filter_Expression

Optional. Default = .T. (all records). A character filter expression that evaluates to a logical value. If Filter is specified, only the records in the source table that satisfy the filter are copied. If Filter is not specified, the currently selected records in the source table are copied.

Description

Copies records to another table with similar structure

Discussion

The <TBL>.COPY_RECORDS_TO() method copies records in the source table referenced by <TBL> to the target table specified by Table_Name. Data is copied from each field in the source table to the corresponding field with the same name in the target table. Result is a character string that indicates how many records were copied, and how many records could not be copied because they violated a field rule in the target table. For example, if Result is "230,3", it indicates that 230 records were copied and 3 records were not copied because of a field rule violation. The "violated" table in the Alpha Anywhere program folder shows which records were not copied. Table_Name can have more fields than the source table. However, at a minimum, it must have all of the fields in the source table, and they must be of the same type and size.

This script copies current selection of records to "OLD_CUSTOMERS"

dim tbl as P
tbl_source = table.open("customers")
query.filter = "state = 'ma'"
indx = tbl_source.query_create()
result = tbl_source.copy_records_to("OLD_CUSTOMERS")
ui_msg_box("Result", word(result, 1) + " Records copied. " + word(result, 2) + " Records not copied (see Violated table).")
tbl_source.close()

This script copies customers from "MA" to "OLD_CUSTOMERS"

dim tbl as P
tbl_source = table.open("customers")
result = tbl_source.copy_records_to("OLD_CUSTOMERS","state = 'ma'")
ui_msg_box("Result", word(result, 1) + " Records copied. " + word(result, 2) + " Records not copied (see Violated table).")
tbl_source.close()

See Also